from selenium.webdriver.common.by import By

from common.Uilt import forum_driver


class register:
    driver = ""
    def __init__(self):
        self.driver = forum_driver.driver

    #成功注册
    def RegisterSuc(self):
        self.driver.get("http://127.0.0.1:58080/sign-in.html")
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page.page-center > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a").click()

        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("admin04")
        self.driver.find_element(By.CSS_SELECTOR,"#nickname").send_keys("admin04")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("admin04")
        self.driver.find_element(By.CSS_SELECTOR,"#passwordRepeat").send_keys("admin04")
        self.driver.find_element(By.CSS_SELECTOR,"#policy").click()#勾选同意条款
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()

        ret = self.driver.find_element(By.CSS_SELECTOR,"body > div > div > div > div:nth-child(1) > div > div.card.card-md > div > h2").text
        assert ret == "用户登录" #判断是否成功注册返回
        forum_driver.getwinshot()


    #空白注册
    def Register_Null_Fail(self):
        self.driver.get("http://127.0.0.1:58080/sign-in.html")
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page.page-center > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a").click()

        self.driver.find_element(By.CSS_SELECTOR,"#policy").click()
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()

        ret = self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > h2").text
        assert ret == "用户注册"#判断是否未成功注册
        forum_driver.getwinshot()
    #未勾选注册
    def Register_Not_selected_fail(self):
        self.driver.get("http://127.0.0.1:58080/sign-in.html")
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page.page-center > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a").click()

        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("admin04")
        self.driver.find_element(By.CSS_SELECTOR,"#nickname").send_keys("admin04")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("admin04")
        self.driver.find_element(By.CSS_SELECTOR,"#passwordRepeat").send_keys("admin04")
        #self.driver.find_element(By.CSS_SELECTOR,"#policy").click()#勾选同意条款
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()

        ret = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > h2").text
        assert ret == "用户注册"  # 判断是否未成功注册
        forum_driver.getwinshot()

register = register()

register.RegisterSuc()
register.Register_Null_Fail()
register.driver.back()
register.Register_Not_selected_fail()
register.driver.quit()